import 'dart:developer';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:kasax_demos2/gankio/widget/refreshale_widget.dart';

import 'mz_subcategory_list_page.dart';

/// 分类
class MzCategoryPage extends StatefulWidget {
  const MzCategoryPage({Key? key}) : super(key: key);

  @override
  _MzCategoryPageState createState() => _MzCategoryPageState();
}

class _MzCategoryPageState extends State<MzCategoryPage> {
  List<MzSubCategoryListPage> pages = [
    MzSubCategoryListPage("Article"),
    MzSubCategoryListPage("GanHuo"),
    MzSubCategoryListPage("Girl"),
  ];

  // Widget currentPage = MzSubCategoryListPage("Article");
  int _crrentIndex = 0;
  Map<int, String> titles = {0: '专题', 1: '干货', 2: '妹子图'};

  @override
  Widget build(BuildContext context) {
    /// 局部刷新可以使用bloc,provider替换
    var _reshableView = RefreshableView(builder: (BuildContext context) {
      return pages[_crrentIndex];
    });
    return Container(
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
              color: Colors.grey[200], width: 85, child: _buildLeftMenu()),
          _reshableView
          // pages[_crrentIndex]
        ],
      ),
    );
  }

  TextStyle buildTextStyle(int index) {
    return TextStyle(
        color: _crrentIndex == index ? Colors.lightBlueAccent : Colors.green);
  }

  _buildLeftMenu() {
    return ListView.separated(
        itemBuilder: (context, index) {
          return ListTile(
            onTap: () {
              setState(() {
                _crrentIndex = index;
              });
            },
            title: Text(
              "${titles[index]}",
              style: TextStyle(
                  color:
                      _crrentIndex == index ? Colors.lightBlue : Colors.green,
                  fontSize: 14),
            ),
          );
        },
        separatorBuilder: (context, index) {
          return Divider();
        },
        itemCount: titles.length);
  }
}
